﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FreedomX2.Core.Transport.RegistryProvider
{
    public static class Registry
    {
        private static void SetRegistryKey(string name, object obj, string path, RegistryValueKind type)
        {
            RegistryKey rk = Microsoft.Win32.Registry.LocalMachine;
            RegistryKey srk = rk.OpenSubKey("software", true);
            if (srk.OpenSubKey(path) == null)
                srk.CreateSubKey(path);
            RegistryKey crk = srk.OpenSubKey(path, true);
            crk.SetValue(name, obj, type);
            rk.Close();
            srk.Close();
            crk.Close();
        }
        private static void SetRegistryKey(string name, object obj, string path)
        {
            RegistryKey rk = Microsoft.Win32.Registry.LocalMachine;
            RegistryKey srk = rk.OpenSubKey("software", true);
            if (srk.OpenSubKey(path) == null)
                srk.CreateSubKey(path);
            RegistryKey crk = srk.OpenSubKey(path, true);
            crk.SetValue(name, obj);
            rk.Close();
            srk.Close();
            crk.Close();
        }
        private static object GetRegistryValue(string name, string path)
        {
            string p = "Software\\" + path;
            RegistryKey rk = Microsoft.Win32.Registry.LocalMachine;
            RegistryKey subrk = rk.OpenSubKey(p);
            return subrk.GetValue(name);
        }
    }
}
